package cn.sundat.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import cn.sundat.model.Category;

public class CategoryDaoImpl extends HibernateDaoSupport implements CategoryDao{

	public List<Category> findCategoryAll() {
		Query query = currentSession().createQuery("from Category");
		  query.setFirstResult(0); //开始记录 
		  query.setMaxResults(8);  //查询出来的记录数 
//		  query.list();   
//		List<Category> find = (List<Category>) this.getHibernateTemplate().find("from Category");
		return query.list();
	}

	public List<Category> findCategoryByCode() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Category.class);
		criteria.add(Restrictions.eq("state", 0));
		List<Category> list = (List<Category>) this.getHibernateTemplate().findByCriteria(criteria);
		return list;
	}

}
